﻿namespace NJQuery {
	using System;
	using System.ComponentModel;
	using System.Web.UI;
	using System.Diagnostics.CodeAnalysis;

	/// <summary>
	/// Server control used to define the properties of a <see href="http://docs.jquery.com/UI/Effects/Transfer">jQuery UI Transfer effect</see>, which transfers the outline of an element to another element.  This is very useful when trying to visualize interaction between two elements.
	/// The transfer element iself has the class name "ui-effects-transfer", and needs to be styled by you, for example by adding a background or border.
	/// </summary>
	public class TransferEffect : EffectBase {


		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="TransferEffect"/> class.
		/// </summary>
		public TransferEffect() : base("transfer") { }

		#endregion


		#region Properties: Initialization options

		/// <summary>
		/// Optional class name the transfer element will receive (in addition to "ui-effects-transfer").
		/// This property maps directly to the "className" option when the jQuery UI effect is initialized.
		/// </summary>
		[DefaultValue(""), Category("Behavior"), CssClassProperty]
		public virtual string ClassName {
			get { return ViewState["ClassName"] as string ?? string.Empty; }
			set { ViewState["ClassName"] = value; }
		}

		//TODO: Figure out a way to allow jQuery selector syntax be extended to include a server control reference... "~#ServerControlId" maybe?

		/// <summary>
		/// A jQuery selector specifying the element to transfer to.
		/// This property maps directly to the "to" option when the jQuery UI effect is initialized.
		/// </summary>
		[DefaultValue(""), Category("Behavior")]
		[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "To", Justification = "Using jQuery UI naming, for better or worse.")]
		public virtual string To {
			get { return ViewState["To"] as string ?? string.Empty; }
			set { ViewState["To"] = value; }
		}

		#endregion


		#region Methods: Rendering hooks

		/// <summary>
		/// Allows a jQuery server control to reference scripts and stylesheets necessary to render their client markup and widgets.
		/// </summary>
		/// <param name="manager">The <see cref="Manager"/> used to handle style and script referencing in addition to unified generation of load and ready scripts.</param>
		protected override void Register(Manager manager) {
			base.Register(manager);

			manager.RegisterClientScript(ClientScript.UITransferEffect);
		}

		/// <summary>
		/// Returns a <see cref="PropertyCollection"/> containing option values specific to the effect.
		/// This method is used primarily by control developers.
		/// </summary>
		/// <returns>A <see cref="PropertyCollection"/> containing the effect's option values.</returns>
		protected override PropertyCollection CreateOptionProperties() {
			PropertyCollection properties = base.CreateOptionProperties();

			string className = ClassName ?? string.Empty;
			if(className.Length != 0) properties.AddValue("className", className);

			string to = To ?? string.Empty;
			if(to.Length != 0) properties.AddValue("to", to);

			return properties;
		}

		#endregion


	}

}